package org.wlc.demov3.impl;

import org.wlc.demov1.AuthService;
import org.wlc.demov1Impl.AuthInfo;
import org.wlc.demov3.AuthLink;

import java.text.ParseException;
import java.util.Date;

/**
 * @author 王立朝
 * @date 2022/5/17
 * @description:
 */
public class Level2AuthLink extends AuthLink {

    private Date beginDate = f.parse("2022-05-11 00:00:00");
    private Date endDate = f.parse("2022-05-20 23:59:59");


    public Level2AuthLink(String levelUserId, String levelUserName) throws ParseException {
        super(levelUserId, levelUserName);
    }

    /**
     * 这是每一个实现者必须实现的类，不同的审核级别处理不同的业务
     *
     * @param uid
     * @param orderId
     * @param authDate
     * @return
     */
    @Override
    public AuthInfo doAuth(String uid, String orderId, Date authDate) {

        Date date = AuthService.queryAuthInfo(levelUserId, orderId);
        if (null == date) {
            return new AuthInfo("0001", "单号：", orderId, " 状态：待二级审批负责人 ", levelUserName);
        }

        AuthLink next = super.next();
        if (null == next) {
            return new AuthInfo("0000", "单号：", orderId, " 状态：二级审批完成负责人", " 时间：",
                    f.format(date), " 审批人：", levelUserName);
        }
        if (authDate.before(beginDate) || authDate.after(endDate)) {
            return new AuthInfo("0000", "单号：", orderId, " 状态：二级审批完成负责人", " 时间：",
                    f.format(date), " 审批人：", levelUserName);
        }


        return next.doAuth(uid, orderId, authDate);
    }
}
